package ls.ch02.demo;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;


import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;

/**
 * @author ls
 * @Date 创建时间:2022/4/6 14:04
 * 描述:
 */

public class Demo3 {
    public static void main(String[] args) throws ParserConfigurationException, IOException, SAXException {
        //得到 DOm 解析器的工厂实例
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        //从 DOM 工厂获得 DOM 解析器
        DocumentBuilder db = dbf.newDocumentBuilder();
        //解析 XML 文档，得到一个 Document 对象，即 DOM 树
        Document doc = db.parse("F:\\idea\\S3-All\\frame\\src\\ls\\ch02\\demo\\Demo2.xml");


        NodeList list = doc.getElementsByTagName("pubDate");
        Element pubDateElement =(Element) list.item(0);
        String pubDate = pubDateElement.getFirstChild().getNodeValue();
        System.out.println(pubDate);
    }
}
